package com.googlecode.kipler.syntax.concept;

import com.googlecode.kipler.syntax.LTLUnaryOperator;


public class LTLUnaryConcept extends Concept {

	private LTLUnaryOperator constructor;

	private Concept operand;

	public LTLUnaryConcept() {

	}

	public LTLUnaryConcept(LTLUnaryOperator constructor, Concept concept) {
		setConstructor(constructor);
		setOperand(concept);
	}

	public LTLUnaryOperator getConstructor() {
		return constructor;
	}

	public void setConstructor(LTLUnaryOperator constructor) {
		this.constructor = constructor;
	}

	public Concept getOperand() {
		return operand;
	}

	public void setOperand(Concept concept) {
		this.operand = concept;
	}

	@Override
	public boolean isNegated() {
		return false;
	}

	@Override
	public Concept toggleNegated() {
		if (getConstructor().equals(LTLUnaryOperator.SOMETIME)) {
			setConstructor(LTLUnaryOperator.ALWAYS);
		} else if (getConstructor().equals(LTLUnaryOperator.ALWAYS)){
			setConstructor(LTLUnaryOperator.SOMETIME);
		}
		// nothing to do for next operator
		setOperand(getOperand().toggleNegated());
		return this;
	}

	@Override
	public void accept(ConceptVisitor v) {
		v.visitLTLUnaryConcept(this);
	}

	@Override
	public boolean equals(Object obj) {
		if (obj != null && (obj.getClass().equals(this.getClass()))) {
			LTLUnaryConcept other = (LTLUnaryConcept) obj;
			return (this.getConstructor().equals(other.getConstructor()) && this
					.getOperand().equals(other.getOperand()));
		}
		return false;
	}

	@Override
	public int hashCode() {
		return 17 * 37 + super.hashCode() + getConstructor().hashCode()
				+ getOperand().hashCode();
	}

	public LTLUnaryConcept copy() {
		LTLUnaryConcept result = new LTLUnaryConcept();
		result.setConstructor(getConstructor());
		result.setOperand(getOperand().copy());
		return result;
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append(getConstructor());
		buffer.append("(");
		buffer.append(getOperand());
		buffer.append(")");
		return buffer.toString();
	}

}
